package com.chess.annotation.demo;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class MainActivity extends Activity implements AnnotationDelegate {

	private RelativeLayout topView = null;

	private int widthDefault = 0;
	private int heightDefault = 0;
	private boolean addText = true;
	private List<AnnotationView> signatureListView = new ArrayList<AnnotationView>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		topView = (RelativeLayout)this.findViewById(R.id.topView);
		widthDefault = (int)getResources().getDimension(R.dimen.annotation_default_width);
		heightDefault = (int)getResources().getDimension(R.dimen.annotation_default_height);
		// doAddAnnotation();
		// doAddZoomImageView();
	}

	public void addAnnotation(View view) {

		doAddAnnotation();
	}

	private void doAddAnnotation() {

		LayoutParams paras = new LayoutParams(widthDefault, heightDefault);
		paras.addRule(RelativeLayout.CENTER_IN_PARENT);
		AnnotationView view = addText ? new AnnotationTextView(MainActivity.this, "Keep calm & carry on")
				: new AnnotationImageView(MainActivity.this);
		view.setDelegate(MainActivity.this);
		topView.addView(view, paras);
		signatureListView.add(view);
		postInitParam(view);
		addText = !addText;
	}

	@Override
	public void doEdit(View annotationViewToBeUpdated) {
		// TODO Auto-generated method stub

	}

	@Override
	public void doResize(View annotationViewToBeUpdated) {
		// TODO Auto-generated method stub

	}

	@Override
	public void postDelete(View annotationViewToBeUpdated) {
		signatureListView.remove(annotationViewToBeUpdated);
	}

	@Override
	public void setAnnotationViewSize(int width, int height) {
		// TODO Auto-generated method stub

	}

	@Override
	public int getTitleBarViewBottom() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int[] getImageDocumentTopAndBottom() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void postInitParam(View annotationViewToBeUpdated) {
		for (AnnotationView item : signatureListView) {
			if (item!=annotationViewToBeUpdated) {
				item.setOperationInvisible();
			}else {
				item.setOperationVisible();
			}
		}
	}
}